package com.cy.store.Interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 定义一个拦截器
 * @author 元曦
 * @create 2022-11-27 11:28
 */
public class LoginInterceptor implements HandlerInterceptor{
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object obj = request.getSession().getAttribute("uid");
        if (obj == null){
            //重定向到登陆页面
            response.sendRedirect("/web/login.html");
            //结束后续的调用
            return false;
        }
        //放行
        return true;
    }
}
